﻿using System;
using _5E.Infrastructure.Domain;
using _5E.Infrastructure.String;

namespace WholesaleOnline.Model
{
    partial class WoAccount : EntityBase<Guid>, IAggregateRoot
    {
        public virtual bool CheckPassword(string password)
        {
            return string.IsNullOrEmpty(BcryptPwd) ? CheckByMD5(password) : BcryptPwd.CompareByBCrypt(password);
        }

        private bool CheckByMD5(string password)
        {
            string md5Pwd = password.ToMD5().Replace("-", "").ToLower();

            if (!string.IsNullOrEmpty(m_Md5Salt))
                md5Pwd = (md5Pwd + Md5Salt).ToMD5().Replace("-", "").ToLower();

            return md5Pwd == Md5Pwd;
        }

        protected override void Validate()
        {
            throw new System.NotImplementedException();
        }
    }
}
